<?php

/**
 * Botenmakrt Front-end
 * 
 * Domain Objects
 * 
 * Calendar_domainObject Class File
 *
 * @category    botenmarkt_front
 * @package     library
 * @subpackage  domainObjects
 * 
 * @author      valerii lazarevych <valeriy.fremar@gmail.com>
 * @copyright   fremar ltd.
 * 
 * @license     default
 * @version     6:39:24 PM | Jan 24, 2012
 */

/**
 * Calendar_domainObject domain Class
 * 
 * Represent calendar event enteties
 */
class   Calendar_domainObject       extends     domainObject
{
    /**
     * Calendar event title
     * 
     * @var string
     */
    public      $title              =       null;
    
    /**
     * Event city
     * 
     * @var string
     */
    public      $city               =       null;
    
    /**
     * Event province
     * 
     * @var string
     */
    public      $province           =       null;
    
    /**
     * Event description
     * 
     * @var string
     */
    public      $description        =       null;
    
    /**
     * Event begin date
     * 
     * @var int  |   Unix time stamp
     */
    public      $start_date         =       null;
    
    /**
     * Event end date
     * 
     * @var int |   Unix time stamp
     */
    public      $end_date           =       null;
    
    /**
     * Event type
     * 
     * @var int
     */
    public      $event_type         =       null;
    
    /**
     * Event website url
     * 
     * @var string  |   url
     */
    public      $website            =       null;
    
    /**
     * Event email
     * 
     * @var string
     */
    public      $email              =       null;
    
    /**
     * Event phone number
     * 
     * @var int
     */
    public      $phonenumber        =       null;
    
    /**
     * Event actual status
     * 
     * @var bool
     */
    public      $status             =       null;
    
    /**
     * Event email available status
     * 
     * @var bool
     */
    public      $emailstatus        =       null;
    
    /**
     * Event phone number available status
     * 
     * @var bool
     */
    public      $phonestatus        =       null;
    
    /**
     * Event location status.
     *
     * Out of country = 1     
     * 
     * @var bool
     */
    public      $abroad             =       null;
    
    
    
    /**
     * Get event title
     * 
     * @return string
     */
    public function eventTitle()
    {
        if (!$this->title)            
             $this->title    =   implode(' ', array_slice( str_word_count($this->eventDesc(), '2'), 0, 3 ) );
        
        return $this->title;
    }
    
    /**
     * Get event location city
     * 
     * @return string
     */
    public function eventCity()
    {
        return $this->city;
    }
    
    /**
     * Get event city province
     * 
     * @return string
     */
    public function eventProvince()
    {
        if ( !($this->province instanceof Provinces) ){
            
            $province       =   new Provinces_domainObject();
            $province->         find($this->province);
            $this->province =   $province;        }
        
        return  $this->province;
    }
    
    /**
     * Get event description
     * 
     * @return string
     */
    public function eventDesc()
    {
        return $this->description;
    }
    
    /**
     * Get event begin date
     * 
     * @return int  |  Unix time stamp
     */
    public function eventBegin()
    {
        return $this->start_date;
    }
    
    /**
     * Get event end date
     * 
     * @return int  |   Unix time stamp
     */
    public function eventEnd()
    {
        return $this->end_date;
    }
    
    /**
     * Get event type
     * 
     * @return int
     */
    public function eventType($eventType = '')
    {
        if ($eventType != '')
            $this->event_type   =   $eventType;
        
        return $this->event_type;
    }
    
    /**
     * Get event link
     * 
     * @return string   |   url
     */
    public function eventSite()
    {
        return $this->website ?: '';                
    }
    
    /**
     * Get event email address
     * 
     * @return string
     */
    public function eventEmail()
    {
        return $this->email;
    }
    
    /**
     * Get event phone number
     * 
     * @return int
     */
    public function eventPhone()
    {
        return $this->phonenumber;
    }
    
    /**
     * Get out of country location event status
     * 
     * @return bool
     */
    public function eventAbroad()
    {
        return $this->abroad;
    }
    
    /**
     * Get or Set event publish online status
     * 
     * @param bool $param
     * @return bool
     */
    public function eventStatus($param = null)
    {
        if ($param) {            
            $this->status   =   (int)(bool)$param;        }
            
        return $this->status;
    }

    /**
     * Build $this domain object based on input array of properties
     * 
     * @param array $props
     * @return Calendar_domainObject instance
     */
    public static function build(array $props)
    {
        $own        =   parent::build($props);
        
        $startDate  =   DateTime::createFromFormat('d/m/Y', $own->start_date);
        $endDate    =   DateTime::createFromFormat('d/m/Y', $own->end_date);
        
        $own->start_date    =   strtotime($startDate->format('m/d/Y'));
        $own->end_date      =   strtotime($endDate->  format('m/d/Y'));                
        
        if ($own->eventAbroad() || $own->province == 0){
            $own->province  =   null;        }
            
        if ($own->eventType() == 0) {
            $own->eventType(null);       }
                    
        if ($own->eventAbroad() != '1')
            $own->abroad  =   '0';
               
        return  $own;
    }
    
}

?>
